package net.joint_painting.client.view;

import net.joint_painting.client.observer.ViewObject;
import net.joint_painting.client.observer.ViewObserverListener;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;

/**
 * @author CAM
 * @version $Revision: 1.0 $
 */
public class PainterPicker extends Composite {

    /**
     * @author CAM
     * @version $Revision: 1.0 $
     */
    interface PainterPickerUiBinder extends UiBinder<Widget, PainterPicker> {
    }

    @UiField
    Button small;
    @UiField
    Button medium;

    @UiField
    Button big;

    private ViewObserverListener viewObserverListener;

    private static PainterPickerUiBinder uiBinder = GWT
	    .create(PainterPickerUiBinder.class);

    public PainterPicker() {
	initWidget(uiBinder.createAndBindUi(this));
    }

    /**
     * Method addViewObserver.
     * 
     * @param viewObserverListener
     *            ViewObserverListener
     */
    public void addViewObserver(ViewObserverListener viewObserverListener) {
	this.viewObserverListener = viewObserverListener;
    }

    /**
     * Method onBigClick.
     * 
     * @param event
     *            ClickEvent
     */
    @UiHandler("big")
    void onBigClick(ClickEvent event) {
	viewObserverListener.notify(new ViewObject(this,
		ViewObject.ViewObjectType.SETPAINTERSIZE, 10));
    }

    /**
     * Method onMediumClick.
     * 
     * @param event
     *            ClickEvent
     */
    @UiHandler("medium")
    void onMediumClick(ClickEvent event) {
	viewObserverListener.notify(new ViewObject(this,
		ViewObject.ViewObjectType.SETPAINTERSIZE, 5));
    }

    /**
     * Method onSmallClick.
     * 
     * @param event
     *            ClickEvent
     */
    @UiHandler("small")
    void onSmallClick(ClickEvent event) {
	viewObserverListener.notify(new ViewObject(this,
		ViewObject.ViewObjectType.SETPAINTERSIZE, 1));
    }
}
